<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>事件监听</title>
</head>
<body>

<ul id="no">
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
</ul>

<script>
    var ul = document.getElementById("no")
    var li = ul.getElementsByTagName("li")
    for (var i =0; i<li.length;i++){
        li[i].onclick=function(){alert(i)}


}
</script>

</body>
</html>